import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { CompanyVO } from '../vo/CompanyVO';
import { ApiService } from '../api/api.service';
import { ApiUrl } from '../api/ApiUrl';
@Component({
  selector: 'app-companylist',
  templateUrl: './companylist.page.html',
  styleUrls: ['./companylist.page.scss'],
})
export class CompanylistPage implements OnInit {
  items: CompanyVO[] = [];
  items1: CompanyVO[] = [];
  items2: CompanyVO[] = [];
  items3: CompanyVO[] = [];
  goToDetails(iid) {
    console.log(iid);
    this.router.navigate(['/companydetail', {'iid': iid}]);
  }
  goToMore(itype) {
      console.log(itype);
      this.router.navigate(['/companymore', {'itype': itype}]);
  }
  constructor(private router: Router, public api: ApiService) { }

  ngOnInit() {
    this.onSearch();
  }
  onSearch() {
    this.api.getItems<CompanyVO>(ApiUrl.getCompanyList, {}).subscribe(response => {
      if (response === null || response.length === 0) {
        console.log('没有数据返回');
        return;
      }
      this.items = response;
      for (let i = 0; i < this.items.length; i++) {
        if (this.items[i].itype === 1) {
          this.items1.push(this.items[i]);
        }
        if (this.items[i].itype === 2) {
          this.items2.push(this.items[i]);
        }
        if (this.items[i].itype === 3) {
          this.items3.push(this.items[i]);
        }
      }
    }, () => {
      console.log('出错了');
    });
  }
}
